package org.example.factory.simple.abs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author
 * @description
 */
public class OrderPizza {

    AbsFactory absFactory;//聚合

    public OrderPizza(AbsFactory absFactory){
        setAbsFactory(absFactory);
    }

    private void setAbsFactory(AbsFactory absFactory){
        Pizza3 pizza = null;
        String orderType = "";
        this.absFactory = absFactory;
        do {
            orderType = getType();
            pizza= absFactory.createPizza3(orderType);
            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
                System.out.println("您订购的" + pizza.getName() + "准备完毕");
            } else {
                System.out.println("订购失败");
                break;
            }


        }while (true);
    }

    //写一个方法，获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin =
                    new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入Pizza类型:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
